package util.greedy;

import bean.Task;
import bean.Worker;

import java.util.HashSet;

public class ArgMax {

    /**
     * Top1贪心算法 的第三行
     * first round，找出当前工人集合中效用最大一个的工人
     * @param workers 工人集合
     * @param task 一个任务
     * @param team 组建的队伍g
     */
    public static Worker argMax(HashSet<Worker> workers, Task task, HashSet<Worker> team) {
        double argMax = 0;
        Worker maxWorker = null;
        for (Worker worker : workers) {
            int maxItem1 = MaxItem1.maxItem(team,task.getSkills());
            int maxItem2 = MaxItem2.maxItem(team,worker,task.getSkills());
            double value = (maxItem2 - maxItem1) / worker.getPayoff();
            if ( value>argMax ) {
                argMax = value;
                maxWorker = worker;
            }
        }
//        if (maxWorker != null) {
//            System.out.println(argMax);
//            System.out.println(maxWorker);
//            System.out.println("---------------------");
//        }
        return maxWorker;
    }
}
